package com.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author wsx
 * @create 2018/08/29
 */
@RequestMapping
@Controller
public class ThymeleafController {

	@GetMapping("/home/{number}")
	public String home(@PathVariable String number, HttpServletRequest request) {
		request.setAttribute("title", "动态" + number);
		return "home";
	}

	@GetMapping("/home1")
	public ModelAndView home1() {
		ModelAndView mode = new ModelAndView();
		mode.setViewName("home");
		mode.addObject("title", "动态2");
		return mode;
	}

	@GetMapping("/index")
	public ModelAndView index() {
		ModelAndView view = new ModelAndView();
		// 设置跳转的视图 默认映射到 src/main/resources/templates/{viewName}.html
		view.setViewName("index");
		// 设置属性
		view.addObject("title", "我的第一个WEB页面");
		view.addObject("desc", "欢迎进入battcn-web 系统");
		Author author = new Author();
		author.setAge(22);
		author.setName("唐亚峰");
		view.addObject("author", author);
		return view;
	}

	@GetMapping("/index1")
	public String index1(HttpServletRequest request) {
		request.setAttribute("title", "我的第一个web页面");
		request.setAttribute("desc", "欢迎进入xxx-web系统");
		Author author = new Author();
		author.setAge(12);
		author.setName("凡多姆海威夏尔");
		request.setAttribute("author", author);
		return "index";
	}

	class Author {
		private int age;
		private String name;

		public int getAge() {
			return age;
		}

		public void setAge(int age) {
			this.age = age;
		}

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

	}
}
